package com.moore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moore.bean.CareerIntentions;
import com.moore.bean.Work;
import com.moore.mapper.IntentionsMapper;
import com.moore.service.IntentionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IntentionsServiceImpl implements IntentionsService {
    @Autowired
    private IntentionsMapper intentionsMapper;
    @Override
    public List<CareerIntentions> getCareerIntentionsByUserId(int userId) {
        return intentionsMapper.selectCareerIntentionsWithDetails(userId);
    }

    @Override
    public CareerIntentions getCareerIntentionsById(int id) {
        return intentionsMapper.getCareerIntentionsById(id);
    }

    @Override
    public int deleteCareerIntentionsById(int id) {
        QueryWrapper<CareerIntentions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("intentions_id",id);
        return intentionsMapper.delete(queryWrapper);
    }

    @Override
    public int saveCareerIntentions(CareerIntentions careerIntentions) {
        QueryWrapper<CareerIntentions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("intentions_id",careerIntentions.getIntentionsId());
        CareerIntentions careerIntentions1 = intentionsMapper.selectOne(queryWrapper);
        if(careerIntentions1 == null){
            return intentionsMapper.insert(careerIntentions);
        } else {
            return intentionsMapper.updateById(careerIntentions);
        }
    }
}
